import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { GoodsSpecVO, GoodsSpecForm, GoodsSpecQuery } from '@/api/mall/goodsSpec/types';

/**
 * 查询商品规格列表
 * @param query
 * @returns {*}
 */

export const listGoodsSpec = (query?: GoodsSpecQuery): AxiosPromise<GoodsSpecVO[]> => {
  return request({
    url: '/mall/goodsSpec/pageList',
    method: 'get',
    params: query
  });
};
/**
 * 根据商品ID查询商品规格列表
 * @param query
 * @returns {*}
 */

export const specByGoodsIdListApi = (query?: GoodsSpecQuery) => {
  return request({
    url: '/mall/goodsSpec/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询商品规格详细
 * @param id
 */
export const getGoodsSpec = (id: string | number): AxiosPromise<GoodsSpecVO> => {
  return request({
    url: '/mall/goodsSpec/' + id,
    method: 'get'
  });
};

/**
 * 新增商品规格
 * @param data
 */
export const addGoodsSpec = (data: GoodsSpecForm) => {
  return request({
    url: '/mall/goodsSpec',
    method: 'post',
    data: data
  });
};

/**
 * 修改商品规格
 * @param data
 */
export const updateGoodsSpec = (data: GoodsSpecForm) => {
  return request({
    url: '/mall/goodsSpec',
    method: 'put',
    data: data
  });
};

/**
 * 指删除商品规格
 * @param id
 */
export const delGoodsSpecIds = (id: string | number | Array<string | number>) => {
  return request({
    url: '/mall/goodsSpec/' + id,
    method: 'delete'
  });
};
/**
 * 单条删除商品规格
 * @param id
 */
export const delGoodsSpec = (id: string | number) => {
  return request({
    url: '/mall/goodsSpec/' + id,
    method: 'delete'
  });
};
/*删除单条属性值*/
export const delGoodsSpecVal = (id: string | number) => {
  return request({
    url: '/mall/goodsSpecVal/' + id,
    method: 'delete'
  });
};
